package com.wms.service.impl;

import com.wms.entity.AddUser;
import com.wms.entity.User;
import com.wms.dto.UserInfoDto;
import com.wms.exception.BusinessException;
import com.wms.mapper.WAXUserMapper;
import com.wms.service.UserService;
import com.wms.utils.SessionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;


@Service
public class UserServiceImpl implements UserService {
    @Autowired
    WAXUserMapper WAXUserMapper;

    //用户登录 查询
    @Override
    public User querryByMobile(String mobile) {

        return WAXUserMapper.queryByMobile(mobile);
    }

    //新增用户
    @Override
    public int addUser(AddUser user) {
        //获取创建人信息
        UserInfoDto userInfoDto= SessionUtils.get();
        if (userInfoDto == null) {
            throw new BusinessException("请先登录!!"); // 抛出自定义异常
        }
//        SessionUtils.remove();

        user.setCreateBy(userInfoDto.getId());
        user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));


        return WAXUserMapper.addUser(user);
    }
}
